package com.hb.trade.api.im.chat.service.impl;

import com.hb.core.pojo.center.au.dto.UserDTO;
import com.hb.core.pojo.center.au.entity.User;
import com.hb.core.pojo.im.entity.ChatUser;
import com.hb.core.pojo.im.mapper.ChatUserMapper;
import com.hb.trade.api.im.chat.service.ChatUserService;
import com.hb.trade.client.center.UserClient;
import com.hb.trade.api.im.chat.manager.TradeLayImUser;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.fzzn.core.model.msg.Message;
import org.fzzn.core.model.user.layim.LayImUser;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 即时通讯用户记录表 服务实现类
 * </p>
 *
 * @author zhaojk
 * @since 2021-12-30
 */
@Service
public class ChatUserServiceImpl extends ServiceImpl<ChatUserMapper, ChatUser> implements ChatUserService {

    protected final UserClient userClient;

    public ChatUserServiceImpl(UserClient userClient) {
        this.userClient = userClient;
    }

    /**
     * 获取指定用户的基础 LayimUser信息
     *
     * @param chatUserId im_chat_user表id
     * @return
     */
    @Override
    public LayImUser getLayimMine(Long chatUserId) {
        if (chatUserId == null) {
            return null;
        }
        Message<User> userMsg = userClient.getByUserId(chatUserId);
        if (userMsg.isSuccess()) {
            return new TradeLayImUser(userMsg.getData());
        }
        return null;
    }

    /**
     * 获取指定用户的基础 LayimUser信息
     *
     * @param uname au_user表username websocket用户唯一标识
     * @return
     */
    @Override
    public LayImUser getLayimMine(String uname) {
        if (uname == null) {
            return null;
        }
        Message<UserDTO> userMsg = userClient.getByUsername(uname);
        if (userMsg.isSuccess()) {
            return new TradeLayImUser(userMsg.getData());
        }
        return null;
    }
}
